#include<string>
#include<vector>
#include <iostream>


//str是要分隔的字符串，sep是分隔符， arry是将分割后的
int Split(const std::string &str, const std::string &sep, std::vector<std::string> *arry)
{
    int pos = 0, idx = 0;  //查找的空格的地址
    int count = 0;
    while(1)
    {
        //abc def ddd
        //find(要查找的字符， 从哪开始找（偏移量）)
        pos = str.find(sep, idx);
        if(pos == std::string::npos) //没找到
            break;
        if(pos == idx)
        {
            idx = pos + sep.size();
        }

        //找到了(从idx开始查找，截取长度)
        std::string tem = str.substr(idx, pos-idx);
        arry->push_back(tem);
        count++;
        idx = pos + sep.size();
    }


    return count;

}


int main()
{
    std::string str = "abc  def  eee  fx  d  asd";
    std::vector<std::string> arry;
    Split(str, "  ", &arry);

    for(auto &e:arry)
    {
        std::cout<<e<<std::endl;
    }

    return 0;
}